package cn.wolfcode.shop.cloud.common;

public class Result<T> {
    public Result() {
    }

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }

    public Result(int code, String msg, T data) {
        this.code = code;

        this.msg = msg;
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    private int code;
    private String msg;
    private T data;

    public static final int SUCCESS_CODE = 200;
    public static final String SUCCESS_MSG= "操作成功";

    public static final int FAIL_CODE = 500;
    public static final String FAIL_MSG= "系统故障";


    public static Result success(Object data){
        return new Result(SUCCESS_CODE,SUCCESS_MSG,data);
    }

    public static Result success(String msg,Object data){
        return new Result(SUCCESS_CODE,msg,data);
    }

    public static Result error(CodeMsg codeMsg){
        return new Result(codeMsg.getCode(),codeMsg.getMsg(),null);
    }

    public static Result defaultError(){
        return new Result(FAIL_CODE,FAIL_MSG,null);
    }
}
